package org.zuel.boot.demo.controller;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zuel.boot.demo.entity.SysUser;
import org.zuel.boot.demo.service.impl.SessionService;

@RestController
@RequestMapping("/zuel")
public class Controller {

    @Autowired
    private SessionService sessionService;

    @GetMapping("/api/resource")
    public String getResource(HttpServletRequest request) {
        SysUser user = sessionService.validateSession1(request);
        if (user != null) {
            return "Protected resource for user: " + user.getUsername();
        } else {
            return "Access denied";
        }
    }
}